package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogPawnshopRepair;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogPawnshopRepairDaoImpl extends TempDao {

	public boolean addLogPawnshopRepairList(List<LogPawnshopRepair> list) {
		boolean result = false;
		getDb().setConnName(DbNameStrategy.getLogDb());
		String sql = "INSERT INTO t_l_pawnshop_repair(userId,activityId,itemId,startReceptionCount,repairTime,oldStatus,nowStatus,oldPrice,nowPrice," +
				"`time`) VALUES(?,?,?,?,?,?,?,?,?,?)";
		List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
		for (LogPawnshopRepair data : list) {
			Map<Integer, DbParameter> para = new HashMap<>();
			int i = 1;
			para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
			para.put(i++, new DbParameter(Types.BIGINT, data.getItemId()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getStartReceptionCount()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getRepairTime()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getOldStatus()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getNowStatus()));
			para.put(i++, new DbParameter(Types.BIGINT, data.getOldPrice()));
			para.put(i++, new DbParameter(Types.BIGINT, data.getNowPrice()));
			para.put(i++, new DbParameter(Types.TIMESTAMP,new Timestamp(data.getTime())));
			mapList.add(para);
		}

		if (getDb().executeBatchQuery(sql, mapList) > -1) {
			result = true;
		}
		return result;
	}
}
